#!/bin/bash

# 设置日志路径
LOGDIR=/mnt/DG/DATA/LOG/sys_start

# 判断是否有revive文件，没有退出
if [ ! -d "${LOGDIR}" ]; then
    mkdir ${LOGDIR}
fi

# 判断是否有 log 文件，没有则创建
filename=$(date +%Y%m%d)_$(date +%H%M%S).log
if [ ! -f "${LOGDIR}/$filename" ]; then
    touch ${LOGDIR}/$filename
fi

currentdate=$(date +%Y/%m/%d-%H:%M:%S)
LOGFILE=${LOGDIR}/$filename

#打印信息
echo $currentdate "sys power on ..." >> ${LOGFILE}
echo "关闭笔记本自带摄像头 ..." >> ${LOGFILE}
echo 0 | sudo tee /sys/bus/usb/devices/1-5/bConfigurationValue

echo "开启nfs共享文件夹 ..." >> ${LOGFILE}
sudo service nfs-kernel-server restart
# echo "xxx" | sudo -S sh service nfs-kernel-server restart
# ps -aux|grep -v grep|grep nfs >> ${LOGFILE}

echo "检查 /usr/local/go/bin..." >> ${LOGFILE}
function isexist()
{
    source_str=$1
    test_str=$2

    echo $source_str
    echo $test_str

    strings=$(echo $source_str | sed 's/:/ /g')
    for str in $strings
    do
        if [ $test_str = $str ]; then
            return 0
        fi
    done
    return 1
}

echo ${PATH}

if isexist $PATH /usr/local/go/bin; then
  echo "no need to set go ..."  >> ${LOGFILE}
else
  echo "need to set go..."  >> ${LOGFILE}
  export PATH=$PATH:/usr/local/go/bin
fi
